home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / cheeky_c.swf / scripts / frame_3 / DoAction.as
Encoding:
Text File  |  2010-08-12  |  4.5 KB  |  178 lines

  1. function startKick()
  2. {
  3.    if(_root.kicker_mc._currentframe == 1 && !_root.help_mc._visible)
  4.    {
  5.       var xp = _root.goalpost_mc._xmouse;
  6.       var yp = _root.goalpost_mc._ymouse;
  7.       _root.runtime.flag = "in";
  8.       if(xp < 10 || 170 < xp || yp < 10 || 80 < yp)
  9.       {
  10.          _root.runtime.flag = "out";
  11.       }
  12.       var xregion = checkXPosition(xp);
  13.       var yregion = checkYPosition(yp);
  14.       if(_root.runtime.winChance >= Math.random() && _root.runtime.flag == "in")
  15.       {
  16.          _root.runtime.isThisAGoal = true;
  17.       }
  18.       _root.runtime.pos = _root.runtime.flag + "x" + xregion + "y" + yregion;
  19.       _root.kicker_mc.gotoAndPlay("kick");
  20.    }
  21. }
  22. function resetKick()
  23. {
  24.    _root.updateDisplay();
  25.    _root.kicker_mc.gotoAndStop(1);
  26.    _root.ball_mc.gotoAndStop(1);
  27.    _root.crowd_mc.gotoAndStop(1);
  28.    _root.goalie_mc.gotoAndStop(1);
  29.    _root.runtime.isThisAGoal = false;
  30.    _root.runtime.crowdLoop = 0;
  31. }
  32. function kickBall()
  33. {
  34.    var goaliePos = _root.runtime.pos;
  35.    if(_root.runtime.isThisAGoal)
  36.    {
  37.       var goaliePos = getAnotherGoaliePos(_root.runtime.pos);
  38.    }
  39.    _root.ball_mc.gotoAndPlay(_root.runtime.pos);
  40.    _root.goalie_mc.gotoAndPlay(goaliePos);
  41. }
  42. function getAnotherGoaliePos(pos)
  43. {
  44.    var newPos = pos;
  45.    xp = 3;
  46.    while(newPos == pos || xp == 2)
  47.    {
  48.       var xp = Math.round(2 * Math.random() + 1);
  49.       var yp = Math.round(1 * Math.random() + 1);
  50.       newPos = "inx" + xp + "y" + yp;
  51.    }
  52.    return newPos;
  53. }
  54. function checkYPosition(yp, o1, o2)
  55. {
  56.    var pos;
  57.    if(45 >= yp)
  58.    {
  59.       pos = 1;
  60.    }
  61.    else
  62.    {
  63.       pos = 2;
  64.    }
  65.    return pos;
  66. }
  67. function checkXPosition(xp)
  68. {
  69.    var pos;
  70.    if(xp < 42)
  71.    {
  72.       pos = 1;
  73.    }
  74.    else if(xp >= 42 && xp < 74)
  75.    {
  76.       pos = 2;
  77.    }
  78.    else if(xp >= 74 && xp < 106)
  79.    {
  80.       pos = 3;
  81.    }
  82.    else if(xp >= 106 && xp < 138)
  83.    {
  84.       pos = 4;
  85.    }
  86.    else
  87.    {
  88.       pos = 5;
  89.    }
  90.    return pos;
  91. }
  92. function hitGoalPost()
  93. {
  94.    _root.goalpost_mc.gotoAndPlay("shake");
  95. }
  96. function goal()
  97. {
  98.    if(_root.runtime.isThisAGoal)
  99.    {
  100.       _root.runtime.score = _root.runtime.score + 1;
  101.       _root.kicker_mc.gotoAndPlay("goal");
  102.       _root.sound_mc.gotoAndPlay("goal");
  103.       _root.crowd_mc.gotoAndPlay("goal");
  104.    }
  105.    else
  106.    {
  107.       _root.kicker_mc.gotoAndStop("missed");
  108.       _root.sound_mc.gotoAndPlay("missed");
  109.       if(_root.runtime.flag == "in")
  110.       {
  111.          _root.runtime.saves = _root.runtime.saves + 1;
  112.       }
  113.       else
  114.       {
  115.          _root.runtime.misses = _root.runtime.misses + 1;
  116.       }
  117.    }
  118. }
  119. function nextKick()
  120. {
  121.    _root.runtime.kicks = _root.runtime.kicks + 1;
  122.    if(_root.runtime.kicks < _root.runtime.totalKicks)
  123.    {
  124.       _root.resetKick();
  125.    }
  126.    else
  127.    {
  128.       _root.updateDisplay();
  129.       var comment = Math.floor(_root.runtime.score / 2);
  130.       comment = Math.min(comment,5);
  131.       _root.comments_txt = _root.runtime.scoreComments[comment];
  132.       _root.gotoAndPlay("end");
  133.    }
  134. }
  135. function ballCheckGoal()
  136. {
  137.    if(!_root.runtime.isThisAGoal)
  138.    {
  139.       _root.ball_mc.gotoAndPlay("save" + _root.runtime.pos);
  140.    }
  141. }
  142. function updateDisplay()
  143. {
  144.    _root.score_txt = _root.runtime.score;
  145.    _root.kicks_txt = _root.runtime.kicks;
  146.    _root.misses_txt = _root.runtime.misses;
  147.    _root.saves_txt = _root.runtime.saves;
  148. }
  149. function init()
  150. {
  151.    _root.gameID = "cheeky";
  152.    _root.runtime = new Object();
  153.    _root.runtime.pos = 0;
  154.    _root.runtime.score = 0;
  155.    _root.runtime.saves = 0;
  156.    _root.runtime.misses = 0;
  157.    _root.runtime.kicks = 0;
  158.    _root.runtime.totalKicks = 12;
  159.    _root.runtime.winChance = 0.7;
  160.    _root.runtime.flag = "out";
  161.    _root.runtime.scoreComments = new Array();
  162.    _root.runtime.scoreComments[0] = "Let{invalid_utf8=146}s pretend that was the warm up... Quick go again!";
  163.    _root.runtime.scoreComments[1] = "Even great footballers have to start somewhere!";
  164.    _root.runtime.scoreComments[2] = "I think we need to teach this keeper a lesson!";
  165.    _root.runtime.scoreComments[3] = "Not bad... Keep the training up!";
  166.    _root.runtime.scoreComments[4] = "You show great potential - Keep up the good work!";
  167.    _root.runtime.scoreComments[5] = "Goooooaaaaallllllll!!!! Cheeky is the champion!";
  168.    _root.runtime.crowdBg_sound = new Sound();
  169.    _root.runtime.crowdBg_sound.attachSound("crowdBg");
  170.    _root.runtime.crowdBg_sound.setVolume(100);
  171.    _root.runtime.crowdBg_sound.start(0,10000);
  172.    _root.updateDisplay();
  173.    _root.resetKick();
  174. }
  175. stopAllSounds();
  176. init();
  177. stop();
  178.